package com.dhkj.web.utils;

import com.dhkj.web.bean.WXPayCheck;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * 数据返回统一处理  参考https://www.jianshu.com/p/ff619fea7e22
 */
public abstract class WXPayCheckBaseObserver implements Observer<WXPayCheck> {
    private static final String TAG = "WXPayCheckBaseObserver";

    @Override
    public void onNext(WXPayCheck response) {
        //在这边对 基础数据 进行统一处理  举个例子：
        if (response.getTrade_state().trim().equals("SUCCESS")) {
            onSuccess(response.getInfo());
        } else {
            onFailure(null, response.getTrade_state_desc());
        }
    }

    @Override
    public void onError(Throwable e) {//服务器错误信息处理
        onFailure(e, RxExceptionUtil.exceptionHandler(e));
        e.printStackTrace();
    }

    @Override
    public void onComplete() {

    }

    @Override
    public void onSubscribe(Disposable d) {
    }

    public abstract void onSuccess(String result);

    public abstract void onFailure(Throwable e, String errorMsg);

}
